function [Urot, ang] = rotateU(U,stroke,A,species)

    X = [stroke(1,:); stroke(2,:);]';
    
    %plot(X(:,1),X(:,2))
    Xd = sqrt(X(:,1).^2+X(:,2).^2);
    isOX = isoutlier(Xd);
    G = ~isOX;
    idx = G==1;
    ED = fit_ellipse(X(idx,1),X(idx,2));
    try
    Mu = [ED.X0, ED.Y0];    
    catch
        Mu = [0,0];
    end
    if isempty(Mu), Mu = [0,0]; end
    X0 = bsxfun(@minus, X(idx,:), Mu);

    try
        ang = 180*-ED.phi/pi;
    catch
        ang=0;
    end
    
    if isempty(ang), ang = 0; end
    
    %Species exception to rotation
    switch species
        case 'Bull'
           X0 = X;
           ang = 0; 
        case 'Human-low'
           X0 = X;
           ang = 0;
        %case 'Human-high'
        %   X0 = X;
        %   ang = 0;
    end
         
    Rinv = [cosd(ang) -sind(ang); sind(ang) cosd(ang)]; 
    Urot = U(:,1:2)*Rinv;
    %strkRot = Rinv'*X;
    
    figure(777); subplot(1,2,1)
    scatter(stroke(1,:),stroke(2,:),'MarkerEdgeColor','r'); axis image;
    strokeRot = U\A;
    subplot(1,2,2);
    scatter(strokeRot(1,:),strokeRot(2,:),'MarkerEdgeColor','b'); axis image;
end